<?php
function update_amounts( $id )
{
    global $g_betname;
    if ( $id == 0 )
    {
        $rs = getdb( "select id from k_user where acl=4" );
        while ( !$rs->eof )
        {
            update_amounts( $rs->f['id'] );
            $rs->movenext();
        }
    }
    getdb( "update amounts set avail=amount2 where user_id=".$id );
    $rs = getdb( "select * from k_user where enabled=1 and prev_id=".$id );
    while ( !$rs->eof )
    {
        foreach ( $g_betname as $key => $val )
        {
            $rs1 = getdb( "select * from amounts where user_id=".$rs->f['id']." and bettype=".$key );
            if ( !$rs1->eof )
            {
                getdb( "update amounts set avail=avail - ".$rs1->f['amount2']." where user_id=".$id." and bettype=".$key );
            }
        }
        update_amounts( $rs->f['id'] );
        $rs->movenext();
    }
}

if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
exit();
$ui = new UI();
$conf = new Config();
$db = new db();
include( "admin_menu.php" );
update_amounts( 0 );
echo "<p>重算可用额度 完成！</p>";
?>